package com.aust.reflect;

import java.lang.reflect.Constructor;

public class Reflect2 {
    public static void main(String[] args) throws NoSuchMethodException {
        Class<Student> studentClass = Student.class;
        /**
         * 获取所有 public 构造器数组
         */
        Constructor<?>[] constructors1 = studentClass.getConstructors();
        for (Constructor<?> constructor : constructors1) {
            System.out.println(constructor);
        }
        System.out.println("=======================");

        /**
         * 获取所有构造器（包括 private）
         */
        Constructor<?>[] constructors2 = studentClass.getDeclaredConstructors();
        for (Constructor<?> constructor : constructors2) {
            System.out.println(constructor);
        }
        System.out.println("=======================");

        /**
         * 获取 public 构造器
         */
        Constructor<Student> constructor1 = studentClass.getConstructor(String.class, int.class);
        System.out.println(constructor1);
        System.out.println("=======================");

        /**
         * 获取 任意访问权限的构造器
         */
        Constructor<Student> constructor2 = studentClass.getDeclaredConstructor();
        System.out.println(constructor2);
    }
}
